﻿
@{
    ViewData["Title"] = "ReservoirAreaAddIndex";
    Layout = null;
}

<link href="~/libs/layui-v2.5.6/layui/css/layui.css" rel="stylesheet" />
<form class="layui-form" action="">
    <div class="layui-form-item">
        <label class="layui-form-label">库区编码</label>
        <div class="layui-input-block">
            <input type="text" id="areaCode" name="areaCode" lay-verify="required" placeholder="请输入库区编码" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">库区名称</label>
        <div class="layui-input-block">
            <input type="text" id="areaName" name="areaName" lay-verify="required" placeholder="请输入仓库名称" autocomplete="off" class="layui-input">
        </div>
    </div>



    <div class="layui-form-item">
        <label class="layui-form-label">面积</label>
        <div class="layui-input-block">
            <input type="number" lay-affix="number" placeholder="" name="areaCapacity" id="areaCapacity" value="0" class="layui-input">
        </div>
    </div>



    <div class="layui-form-item">
        <label class="layui-form-label">是否冻结</label>
        <div class="layui-input-block">
            <input type="radio" name="isArea" value="true" title="是" checked>
            <input type="radio" name="isArea" value="false" title="否">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">备注</label>
        <div class="layui-input-block">
            <textarea name="resultArea" id="resultArea" placeholder="多行文本框" class="layui-textarea"></textarea>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="submit" class="layui-btn" lay-submit lay-filter="demo1">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            <button type="reset" class="layui-btn layui-btn-primary" onclick="closeWorkstation()">返回</button>
        </div>
    </div>
</form>

<script src="~/libs/layui-v2.5.6/layui/layui.js"></script>
<script src="~/libs/jquery/jquery.js"></script>
<script>
    layui.use(['form', 'laydate', 'util'], function(){
      var form = layui.form;
      var layer = layui.layer;

      // 页面加载完成后执行的函数
      $(function () {
        $('#primaryUnit').val(1);
      });

      // 提交事件
      form.on('submit(demo1)', function(data){
        var field = data.field; // 获取表单字段值

        field.isNot = Boolean(field.isNot);
        $.ajax({
            url:'/ReservoirArea/AddReservoirArea',
            type:'post',
            data:field,
            dataType:'json',
            success:function(res){
                if(res.code==1){
                    layer.alert('添加成功！');
                    closeWorkstation();
                }
                if(res.code==-100){
                    layer.alert('已经有此单位名称！');
                }
            }
        });
        return false; // 阻止默认 form 跳转
      });
    });

    // 关闭弹框
    function closeWorkstation() {
        var index = parent.layer.getFrameIndex(window.name); //先得到当前的索引
        parent.layer.close(index); //再执行关闭
    }
</script>

